package com.example.oos.demo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author HXB
 * @Title:
 * @Description:
 * @date 2020-05-10 10:28
 */
@Slf4j
@RestController
@RequestMapping("qiniu")
@Api(value = "千牛", tags = {"千牛管理接口"})
public class TestQiNiuController {

    @Autowired
    private QiniuService uploadService;


    @RequestMapping(value = "/image", method = RequestMethod.POST)
    @ApiOperation(value = "上传")
    private String postUserInforUpDate(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        try(InputStream in = multipartFile.getInputStream()) {
            log.info("开始上传文件到七牛云");
            return uploadService.uploadFile(in,"1111");
        } catch (IOException e) {
            log.error("上传文件到七牛云失败!");
            return "上传文件到七牛云失败";
        }
    }
}

